<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增实名基本信息')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">

    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-baseInfo-add">
            <h4 class="form-header h4">实名基本信息信息</h4>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">名称：</label>
                <div class="col-sm-8">
                    <input name="name" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">值：</label>
                <div class="col-sm-8">
                    <input name="value" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">elemName：</label>
                <div class="col-sm-8">
                    <input name="elemName" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">类型：</label>
                <div class="col-sm-8">
                    <select name="type" id="type" class="form-control" >
                        <option value="1">多选项</option>
                        <option value="2">单选项</option>
                    </select>
                </div>
            </div>

            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">排序：</label>
                <div class="col-sm-8">
                    <input name="sortWeight" class="form-control" type="text" required>
                </div>
            </div>
            <h4 class="form-header h4">实名子项值信息</h4>
            <div class="row">
                <div class="col-sm-12">
                    <button type="button" class="btn btn-white btn-sm" onclick="addRow()"><i class="fa fa-plus"> 增加</i></button>
<!--                    <button type="button" class="btn btn-white btn-sm" onclick="sub.delRow()"><i class="fa fa-minus"> 删除</i></button>-->
                    <div class="col-sm-12 select-table table-striped">
                        <table id="bootstrap-table"></table>
                    </div>
                </div>
            </div>
        </form>
    </div>

    <div>
        <button type="button"  onclick="submitHandler()" class="btn-primary btn">提交</button>
    </div>

    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var prefix = ctx + "auth/baseInfo"
        $("#form-baseInfo-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-baseInfo-add').serialize());
            }
        }

        $(function() {
            var options = {
                pagination: false,
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                sidePagination: "client",
                columns: [
                //     {
                //     checkbox: true
                // },
                {
                    field: 'index',
                    align: 'center',
                    title: "序号",
                    formatter: function (value, row, index) {
                    	var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                    	return columnIndex + $.table.serialNumber(index);
                    }
                },
                // {
                //     field: 'baseValue',
                //     align: 'center',
                //     title: '',
                //     formatter: function(value, row, index) {
                //         var html = $.common.sprintf("<input class='form-control' type='text' name='authItemInfoList[%s].baseValue' value='%s'>", index, value);
                //         return html;
                //     }
                // },
                // {
                //     field: 'baseName',
                //     align: 'center',
                //     title: '',
                //     formatter: function(value, row, index) {
                //         var html = $.common.sprintf("<input class='form-control' type='text' name='authItemInfoList[%s].baseName' value='%s'>", index, value);
                //         return html;
                //     }
                // },
                // {
                //     field: 'baseType',
                //     align: 'center',
                //     title: '',
                //     formatter: function(value, row, index) {
                //         var html = $.common.sprintf("<input class='form-control' type='text' name='authItemInfoList[%s].baseType' value='%s'>", index, value);
                //         return html;
                //     }
                // },
                {
                    field: 'name',
                    align: 'center',
                    title: '名称',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='authItemInfoList[%s].name' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'value',
                    align: 'center',
                    title: '值',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='authItemInfoList[%s].value' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'showFlag',
                    align: 'center',
                    title: '是否展示',
                    formatter: function(value, row, index) {
                        var checked = value == 1?'checked':'';
                        return '<label class=\"radio-box\"> <input type=\"checkbox\" name=\"showFlag\" value=\"1\" '+checked+'  /> 展示 </label>';
                    }
                },
                {
                    field: 'defaultFlag',
                    align: 'center',
                    title: '单选默认',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf('<label class=\"radio-box\"><input type="checkbox" name="authItemInfoList[%s].defaultFlag" value="1"/>默认</label>', index, value);
                        return html;
                    }
                },
                // {
                //     field: 'createTime',
                //     align: 'center',
                //     title: '',
                //     formatter: function(value, row, index) {
                //         var html = $.common.sprintf("<input class='form-control' type='text' name='authItemInfoList[%s].createTime' value='%s'>", index, value);
                //         return html;
                //     }
                // },
                // {
                //     field: 'updateTime',
                //     align: 'center',
                //     title: '',
                //     formatter: function(value, row, index) {
                //         var html = $.common.sprintf("<input class='form-control' type='text' name='authItemInfoList[%s].updateTime' value='%s'>", index, value);
                //         return html;
                //     }
                // },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var value = $.common.isNotEmpty(row.index) ? row.index : $.table.serialNumber(index);
                        return '<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="sub.delRowByIndex(\'' + value + '\')"><i class="fa fa-remove"></i>删除</a>';
                    }
                }]
            };
            $.table.init(options);
        });

        function addRow() {
            var count = $("#" + table.options.id).bootstrapTable('getData').length;
            var row = {
                index: $.table.serialNumber(count),
                baseValue: "",
                baseName: "",
                baseType: "",
                name: "",
                value: "",
                showFlag: "",
                defaultFlag: "",
                createTime: "",
                updateTime: "",
            }
            sub.addRow(row);
        }
    </script>
</body>
</html>